<?php
// help function

function flush_output($msg)
{
	echo $msg."<br />";  
    ob_flush();
    flush();
    sleep(1);	
}

// 获取应用版本本地的目录
function get_app_version_dir($app_id, $edition_id)
{
	$path = config_item('path');
	return sprintf($path['local_version']."%s/%s/",$app_id, $edition_id);
}

// 获取应用本地的目录
function get_app_dir($app_id)
{
	$path = config_item('path');
	return $path['local_version'].$app_id;
}

function checkSystem()
{
	$result = array();
	$check_functions = array('ssh2_connect');
	$check_dir = array('public');
	$errmsg = array();
	
	//检查ssh2系列函数是否可用
	foreach($check_functions as $function) {
		$color = "";
		if (!function_exists($function)) {
			$color = 'red';
			$msg = $function . "函数不存在，无法通过ssh上传文件至服务器, 需要安装ssh2扩展支持。";
		} else {
			$color = 'green';
			$msg = $function . "函数存在，可以通过ssh上传文件至服务器.";
		}
		echo "<span style='color: {$color}'>{$msg}</span><br />";
	}
	//检查目录是否可写
	foreach($check_dir as $dir) {
		$color = "";
		if (!is_writable($dir)) {
			$color = 'red';
			$msg = $dir . " 目录不可写，应用无法创建文件";
		} else {
			$color = 'green';
			$msg = $dir . " 目录可写，应用可以创建文件";
		}
		echo "<span style='color: {$color}'>{$msg}</span><br />";
	}	
}

// 获取文件的路径，列出文件目录树
function get_file_path($path, $filename)
{
	$file_path = "";
	if ($path)
	{			
		if (strpos($path, ".") > 0)
		{
			$file_path = str_replace('.', '/', $path).'/'.$filename;											
		}
		else
		{	
			$file_path = $path.'/'.$filename;
		}		
	}
	else
	{
		$file_path = $filename;
	}
	return $file_path;
}